$(function() {
    if (typeof(Storage) !== "undefined")
    {   
       
         $('.wd-loading').show();
        $.post(localStorage.domain_app+"/webservice/event/getEventNameList.php", {
            page: 0,
            user_id: localStorage.userID
        }, function(res) {
            $('.wd-list-event-for-invite').html(res.html);
            $('#page').val(res.page);                    
            $('#end_paging').val(res.end_paging);
            save_event_id();
            $('.wd-loading').hide();
        }, "json");

    }
    else
    {
        return false;
    }
    //paging
    var killScroll = false;
    $(window).scroll(function() {
        if ($('#end_paging').val() == 0) {
            if ($(window).scrollTop() > ($(document).height() - $(window).height() - 100)) {
                $('.wd-loading').show();
                if (killScroll == false) {
                    killScroll = true;
                    $.post(localStorage.domain_app+"/webservice/event/getEventNameList.php", {
                        page: $('#page').val(),
                        user_id: localStorage.userID
                     }, function(res) {
                        $('.wd-list-event-for-invite').append(res.html);
                        $('#page').val(res.page);                    
                        $('#end_paging').val(res.end_paging);
                        killScroll = false;
                        $('.wd-loading').hide();
                        save_event_id();
                    }, "json");
                } else {
                    return false;
                }
            }
        }
    });
});
function save_event_id(){
  if (typeof(Storage) !== "undefined")
    {
        $(".select_event").click(function() {
            if($(this).is('[rev]')){
                print_alert($(this).attr("rev")+"'s start time is missing. Please come back to the event screen and make changes.");
                return false;
            }
            sessionStorage.select_event_id = $(this).attr("rel");
            sessionStorage.invite_guest_back="select_event";
            wd_redirect("inviteGuests.html");
            return true;
        });

    }
    else
    {
        return false;
    }
}